package com.study.testSpringBoot.factory;

import com.study.testSpringBoot.enumUtil.ServiceEnum;
import com.study.testSpringBoot.service.IUserService;

public class ChangeServiceBeanFactory {

	public static IUserService getUserService(Integer mark) {
		try {
			System.out.println("初始化service。。。。。");
			String servicePath = ServiceEnum.getPathByMark(mark);
			IUserService instance = (IUserService) Class.forName(servicePath).newInstance();
			return instance;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	private static volatile IUserService instance = null;
	
	private ChangeServiceBeanFactory() {
		
	}
	
	public static IUserService getInstance(Integer mark) {
		if(instance == null) {
			try {
				System.out.println("初始化service。。。。。");
				String servicePath = ServiceEnum.getPathByMark(mark);
				instance = (IUserService) Class.forName(servicePath).newInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return instance;
	}
}
